package br.ufrj.xml.model.persistence.dao.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;

import br.ufrj.xml.model.persistence.dao.TableDAO;
import br.ufrj.xml.model.persistence.entity.ColumnVO;
import br.ufrj.xml.model.persistence.entity.TableVO;

public class TableJdbcDAO extends GenericJdbcDAO<TableVO> implements TableDAO {

	private static final String BASIC_QUERY = "select tablename from pg_tables";
	
	public TableJdbcDAO(Connection connection) {
		super(connection);
	}

	public TableVO mapRow(ResultSet result) throws SQLException {
		int i = 1;
		TableVO tableVO = new TableVO();
		tableVO.setName(result.getString(i++));
		tableVO.setAttributes(new ArrayList<ColumnVO>());
		return tableVO;
	}

	public int count() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void create(TableVO entity) {
		// TODO Auto-generated method stub
		
	}

	public void delete(Integer id) {
		// TODO Auto-generated method stub
		
	}

	public List<TableVO> findAll() {
		return query(BASIC_QUERY + " where upper(schemaname) like '%_DTD%'");
	}

	public List<TableVO> findPageByPage(int firstResult, int maxResults) {
		// TODO Auto-generated method stub
		return null;
	}

	public TableVO read(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	public void update(TableVO entity) {
		// TODO Auto-generated method stub
		
	}

	public List<TableVO> findByNameSchema(String nmSchema) {
		List<TableVO> list = query(BASIC_QUERY + " where upper(schemaname) = ?", 
				new Object[]{ nmSchema.toUpperCase() },
				new int[]{ Types.VARCHAR });
		return list;
	}

}
